package com.vicente.managerdemo.controller;

import com.vicente.managerdemo.common.ResultBean;
import com.vicente.managerdemo.dto.UserQueryDto;
import com.vicente.managerdemo.entity.User;
import com.vicente.managerdemo.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 爬虫作业监控接收人表 前端控制器
 * </p>
 *
 * @author vicente
 * @since 2024-12-03
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * @Description: 分页查询用户信息
     **/
    @PostMapping("/page")
    public ResultBean getPageUser(@RequestBody UserQueryDto queryDto) {
        return userService.queryPage(queryDto);
    }

    /**
     * @Description: 保存或更新用户数据
     **/
    @PostMapping("/save")
    public ResultBean save(@RequestBody User user) {
        if (user.getId() == null) {
            return userService.insertUser(user);
        }
        return userService.updateUser(user);
    }

    /**
     * @Description: 删除用户数据
     **/
    @DeleteMapping("/delete/{id}")
    public ResultBean deleteByPrimaryKey(@PathVariable int id) {
        return userService.deleteById(id);
    }

    /**
     * @Description: 获取所有用户数据
     **/
    @GetMapping("all")
    public ResultBean getAllUsers() {
        return userService.getAllUsers();
    }


}
